<?php
@header('Content-type: text/html;charset=UTF-8');
require_once('check.php');
?>
<?php
if ($_POST["Submit"]) {
    $serviceStationId = str_replace(' ','',$_POST["serviceStationId"]);
    $serviceStationName = str_replace(' ','',$_POST["serviceStationName"]);
    $serviceStationPwd = md5("123456");
    $countyTypeId = str_replace(' ','',$_POST["countyTypeId"]);
    $memo = $_POST["memo"];
    $sql = "select * from servicestation where serviceStationId='$serviceStationId'";
    $rs = mysql_query($sql);
    if (mysql_num_rows($rs) == 1) {
        echo "<script language=javascript>alert('站点编号已存在！');history.back();</script>";

    } else {
        $sql = "insert into servicestation (countyTypeId,serviceStationName,serviceStationPwd,serviceStationId,memo,UserId,companyname)" .
            " values ('$countyTypeId','$serviceStationName','$serviceStationPwd','$serviceStationId','$memo'," . $_SESSION["userId"] . ",'" . $_SESSION["companyname"] . "')";
        mysql_query($sql);
        echo "<script language=javascript>alert('添加成功！');window.location='index.php?pageno=$pageno'</script>";
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>站点添加</title>
    <link rel="stylesheet" href="../images/css.css" type="text/css"/>
    <script type="text/javascript">
        function check() {
            var serviceStationId = document.getElementById("serviceStationId");
            var serviceStationName = document.getElementById("serviceStationName");
            var serviceStationPwd = document.getElementById("serviceStationPwd");
            if (trim(serviceStationId.value) == null || trim(serviceStationId.value) == "") {
                alert("请输入站点编号");
                serviceStationId.focus();
                return false;
            }
            if (trim(serviceStationName.value) == null || trim(serviceStationName.value) == "") {
                alert("请输入站点名称");
                serviceStationName.focus();
                return false;
            }
            if (trim(serviceStationPwd.value) == null || trim(serviceStationPwd.value) == "") {
                alert("请输入站点密码");
                serviceStationPwd.focus();
                return false;
            }

            return true;
        }
        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
</head>
<form id="form1" name="form1" method="post" action="" onsubmit="return check();">
    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" bordercolor="#000000"
           bgcolor="#cccccc">
        <tr>
            <th colspan="2" bgcolor="#FFFFFF">添加站点</th>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">站点编号:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="serviceStationId"
                                                                   id="serviceStationId"/>*
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">站点名称:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="serviceStationName"
                                                                   id="serviceStationName"/>*
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">站点类型:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">
                <select id="countyTypeId" name="countyTypeId">
                    <?php
                    $sql = "select * from countytype order by id desc";
                    $rs = mysql_query($sql);
                    while ($rows = mysql_fetch_assoc($rs)) {
                        ?>
                        <option value="<?php echo $rows["countyTypeId"] ?>"><?php echo $rows["countyTypeName"] ?></option>
                        <?php
                    }
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">站点说明:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">
                <textarea rows="5" cols="15" name="memo"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input name="Submit" type="submit" class="button" value="提交"/>
                &nbsp;
                <input name="Submit2" type="reset" class="button" value="重置"/></td>
        </tr>
    </table>
</form>
</body>
</html>